﻿@model List<HuskyRescue.Core.ViewModel.Blog.Post>

@* Read the current page and total paged *@

@{
	var currentPage = ViewContext.RequestContext.HttpContext.Request["p"] != null
		? int.Parse(ViewContext.RequestContext.HttpContext.Request["p"])
		: 1;

	var totalPages = Math.Ceiling((double)Model.Count / 10);
}

@* Check do we need to display paginatoin links *@

@if (currentPage > 1 || currentPage < totalPages)
{
	var p = string.Format("p={0}", currentPage - 1);
	var n = string.Format("p={0}", currentPage + 1);
	
	@* if the view is rendered for "search" action append the pagination value with "&" *@
	
	if (ViewContext.RouteData.Values["action"].ToString().Equals("search", StringComparison.OrdinalIgnoreCase))
	{
		var s = String.Format("?s={0}", ViewContext.RequestContext.HttpContext.Request.QueryString["s"]);
		p = String.Format("{0}&{1}", s, p);
		n = String.Format("{0}&{1}", s, n);
	}
	else
	{
		p = String.Concat("?", p);
		n = String.Concat("?", n);
	}
	
	<!-- pagination links -->
	<div class="pager">
		<a href="@p" title="Previous" class="previous" style="visibility:@(currentPage > 1 ? "visible" : "collapse")"><< previous</a>

		<a href="@n" title="Next" class="next" style="visibility:@(currentPage < totalPages ? "visible" : "collapse")">next >></a>
	</div>
}